package com.weavernorth.sysap.util;

import com.alibaba.fastjson.JSONObject;
import com.weavernorth.sysap.bean.HrmResource;
import com.weavernorth.sysap.dao.SyncOrgStrucDao;
import com.weavernorth.util.Logger4jUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * SAP拿到信息后,封装人员类
 *
 * @author zm
 * @version v1.0 created by 2019-12-26
 */
public class GetUserMessageUtil extends BaseBean {
//    public static Log log = LogFactory.getLog(GetUserMessageUtil.class.getName());
private Logger log = Logger4jUtil.getLoggerByName("/Timmer/synchronization_log/");
    /**
     * SAP信息封装hrmresource
     *[人员同步新增逻辑:2021-06-11]
     *field159    AD显示名称(AD用), 根据员工号取uf_qjt_adxsmc表,xsmc显示名称字段
     *field160    岗位(AD用) ,取HRMJOBTITLES 岗位中文名称
     *field161    部门(AD用) , 取hrmdepartment的部门中文名称
     *field162    公司(AD用),  取到的分部id作为条件去uf_qjt_syb_jc表查询简称
     * @param jsonUser SAP人员信息
     * @param rs       数据库操作
     * @param sosDao   数据库操作类
     * @return HrmResource 人员信息
     */
    public HrmResource getHrmResource(JSONObject jsonUser, RecordSet rs, SyncOrgStrucDao sosDao) {
        log.info("从sap得到的同步人员数据:" + jsonUser);
        //返回人员信息
        HrmResource hrmResource = new HrmResource();
        //人员姓名：2020-07-28：
        String strLastname = Util.null2String(jsonUser.get("name2"));
        hrmResource.setLastName(strLastname.replaceAll(" ", ""));
        //员工编码
        String strWorkcode = Util.null2String(jsonUser.get("pernr"));
        hrmResource.setWorkCode(strWorkcode);
        //人员状态
        String strStatus = Util.null2String(jsonUser.get("stat2"));
        hrmResource.setStatus(SyncUtil.transformStatus(strStatus));
        //性别 1男,2女
        String strSex = Util.null2String(jsonUser.get("gesch"));
        hrmResource.setSex(SyncUtil.transformSex(strSex));
        //出生日期
        String strBirthday = Util.null2String(jsonUser.get("gbdat"));
        hrmResource.setBirthday(changeDate(strBirthday));
        //民族
        String strNation = Util.null2String(jsonUser.get("racky"));
        String strChangeVal = changeCode("uf_mz", "mzdmsap", "id", strNation, rs);
        hrmResource.setStrNation(strChangeVal);
        //国籍
        String strNationality = Util.null2String(jsonUser.get("natio"));
        String strNationalityVal = changeCode("uf_gj","gjdmsap", "id", strNationality, rs);
        hrmResource.setStrNationality(strNationalityVal);
        //籍贯
        String strNationPlace = Util.null2String(jsonUser.get("gbdep"));
        String strNationPlaceVal = changeCode("uf_jg", "jgdm", "id", strNationPlace, rs);
        hrmResource.setStrNationPlace(strNationPlaceVal);
        //户口所在地
        String strHukouAddress = Util.null2String(jsonUser.get("gbort"));
        hrmResource.setStrHukouAddress(strHukouAddress);
        //户口类型
        String strHukouType = Util.null2String(jsonUser.get("hukot"));
        hrmResource.setStrHukouType(changeHkType(strHukouType));
        //婚姻状态
        String strMaritalstatus = Util.null2String(jsonUser.get("famst"));
        hrmResource.setStrMaritalstatus(changeMaritalType(strMaritalstatus));
        //政治面貌
        String strPolitic = Util.null2String(jsonUser.get("pcode"));
        String strPoliticVal = changeCode("uf_zzmm", "zzmmdm", "id", strPolitic, rs);
        hrmResource.setStrPolitic(strPoliticVal);
        //sap岗位id
        String strJobcode = Util.null2String(jsonUser.get("plans"));
        log.info("SAP岗位id:"+strJobcode);
        //通过岗位编码转换为OA的id
        String strJobtitleid = sosDao.getIdByCode("hrmjobtitles", strJobcode);
        log.info("通过岗位编码转换为OA的id:"+strJobtitleid);
        hrmResource.setJobtitleId(strJobtitleid);
        //部门id,根据岗位id拿到部门id
        //  String strDepartmentcode=Util.null2String(jsonUser.get("objid"));
        String strDepartId = getDepartmentId(strJobtitleid, rs);
        String strSql_log="select jobdepartmentid from hrmjobtitles where id='" + strJobtitleid + "'";
        log.info("根据岗位id查询部门id的Sql:"+strSql_log);
        log.info("根据岗位id查询部门id:"+strJobtitleid);
        hrmResource.setDepartmentId(strDepartId);
        //根据部门id得到分部id
        String strSubId = getSubid(strDepartId, rs);
        String strSql_log2="select subcompanyid1 from hrmdepartment where id='" + strDepartId + "'";
        log.info("根据部门id查询部门id的Sql:"+strSql_log2);
        log.info("根据部门id查询分部id:"+strJobtitleid);
        hrmResource.setSubcompanyId(strSubId);
        //员工组
        String strStaff = Util.null2String(jsonUser.get("persg"));
        String strStaffVal = changeCode("uf_ygz", "ygzdm", "id", strStaff, rs);
        hrmResource.setStrStaff(strStaffVal);
        //员工子组
        String strSubGroup = Util.null2String(jsonUser.get("persk"));
        String strSubGroupVal = changeCode("uf_ygzz", "ygzzdm", "id", strSubGroup, rs);
        hrmResource.setStrSubgroup(strSubGroupVal);
        //人事范围
        String strPersonnelScope = Util.null2String(jsonUser.get("werks"));
        String strPersonnelScopeVal = changeCode("uf_rsfw", "rsfwdm", "id", strPersonnelScope, rs);
        hrmResource.setStrPersonnelScope(strPersonnelScopeVal);
        //人事子范围
        String strPersonnelSubScope = Util.null2String(jsonUser.get("btrtl"));
        String strPersonnelSubScopeVal = changeCode("uf_rszfw", "rszfwdm", "id", strPersonnelSubScope, rs);
        hrmResource.setStrPersonnelSubScope(strPersonnelSubScopeVal);
        //工资核算范围
        String strSalaryScope = Util.null2String(jsonUser.get("abkrs"));
        String strSalaryScopeVal = changeCode("uf_gzfw", "gzhsfw", "id", strSalaryScope, rs);
        log.info("当前工资核算范围值:" + strSalaryScopeVal + ",strSalaryScope:" + strSalaryScope);
        hrmResource.setStrSalaryScope(strSalaryScopeVal);
        //合同类型
        String strContractType = Util.null2String(jsonUser.get("cttyp"));
        String strContractTypeVal = changeCode("uf_htlx", "htlxbm", "id", strContractType, rs);
        hrmResource.setStrContractType(strContractTypeVal);
        //合同结束
        String strContractEndDate = Util.null2String(jsonUser.get("ctedt"));
        hrmResource.setStrContractEndDate(changeDate(strContractEndDate));
        //登录账号
        String strLoginid = Util.null2String(jsonUser.get("ad"));
        //离职后登录账号为空,5为离职
        if (!"5".equals(hrmResource.getStatus())) {
            hrmResource.setStrLoginid(strLoginid);
        }
        //紧急联系人
        String strEmergercy = Util.null2String(jsonUser.get("zxm"));
        hrmResource.setStrEmergency(strEmergercy);
        //紧急联系人电话
        String strEmergencyMobile = Util.null2String(jsonUser.get("zlxys"));
        hrmResource.setStrEmergencyMobile(strEmergencyMobile);
        //证件号
        String strCertificatenu = Util.null2String(jsonUser.get("icnum"));
        hrmResource.setCertificatenu(strCertificatenu);
        //银行名称
        String strBankName = Util.null2String(jsonUser.get("bankl"));
        String strBankNameVal = changeCode("uf_yhmc", "yxdm", "id", strBankName, rs);
        hrmResource.setStrBankName(strBankNameVal);
        //银行卡号
        String strBankCardNo = Util.null2String(jsonUser.get("bankn"));
        hrmResource.setStrBankCardNo(strBankCardNo);
        //是否社聘
        String strSocial = Util.null2String(jsonUser.get("zsp"));
        if ("20".equals(strSocial)) {
            hrmResource.setStrSocial("1");//否
        } else {
            hrmResource.setStrSocial("0");//是
        }

        //转正日期
        String strCurrectDate = Util.null2String(jsonUser.get("zzzrq"));
        hrmResource.setStrCurrectDate(changeDate(strCurrectDate));
        //报销级别
        String strReimbursementLevel = Util.null2String(jsonUser.get("zbxjb"));
        String strReimbursementLevelVal = changeCode("uf_bxjb", "bxjbdm", "id", strReimbursementLevel, rs);
        log.info("报销级别值:strReimbursementLevel:" + strReimbursementLevel + ",strReimbursementLevelVal:" + strReimbursementLevelVal);
        hrmResource.setStrReimbursementLevel(strReimbursementLevelVal);
        //邮箱
        String strEmail = Util.null2String(jsonUser.get("email"));

        hrmResource.setEmail(strEmail);
        //直接上级
        String managerCode = Util.null2String(jsonUser.get("zzjsj"));
        String managerId = sosDao.getIdByCode("hrmresource", managerCode);
        hrmResource.setManagerId(managerId);
        //安全级别
        String seclevel = Util.null2String(jsonUser.get("safe_lvl"));
        hrmResource.setSeclevel(seclevel);
        //是否开通AD
        String strIsOpenAD = Util.null2String(jsonUser.get("is_ad"));
        hrmResource.setStrIsOpenAD(changeAD(strIsOpenAD));
        //是否开通邮箱
        String strIsOpenEmail = Util.null2String(jsonUser.get("is_email"));
        hrmResource.setStrIsOpenEmail(strIsOpenEmail);
        //手机号
        String strMobile = Util.null2String(jsonUser.get("phone"));
        hrmResource.setMobile(strMobile);
        //其它手机号
        String strOtherMobile=Util.null2String(jsonUser.getString("phone2"));
        hrmResource.setMobilecall(strOtherMobile);
        //成本中心
        String strCenter = Util.null2String(jsonUser.get("kostl"));
        log.info("成本中心SAP:" + strCenter);
        String strCenterVal = changeCode("uf_cbzxxx", "cbzx", "id", strCenter, rs);
        log.info("成本中心id:" + strCenterVal);
        hrmResource.setStrCenter(strCenterVal);



        //补充字段开始
        //最后操作日期
        hrmResource.setStrLastmoddate(CommonToSapUtil.getCurDate());
        //最高学历
        String strXl = Util.null2String(jsonUser.getString("slart_xl"));
        String strXlVal = changeCode("uf_xl", "xlbm", "id", strXl, rs);
        hrmResource.setStrDegree(strXlVal);
        //联系方式

        //现居住地
        //税收分组
        String strTaxGrouping = Util.null2String(jsonUser.getString("taxgp"));
        String strTaxGroupingVal = changeCode("uf_ssfzmb", "erssfz", "id", strTaxGrouping, rs);
        hrmResource.setStrTaxGrouping(strTaxGroupingVal);
        //工资发放公司
        String strPayrollCompany = Util.null2String(jsonUser.getString("zgz"));
        hrmResource.setStrPayrollCompany(strPayrollCompany);
        //社保缴纳公司
        String strSocialSecurityCompany = Util.null2String(jsonUser.getString("zzsb"));
        hrmResource.setStrSocialSecurityCompany(strSocialSecurityCompany);
        //公积金缴纳公司
        String strProvidentFundCompany = Util.null2String(jsonUser.getString("zzgjj"));
        hrmResource.setStrProvidentFundCompany(strProvidentFundCompany);
        //首次参加工作日期
        String strWorkStartDate = Util.null2String(jsonUser.getString("zcjgz"));
        hrmResource.setStrWorkStartDate(changeDate(strWorkStartDate));
        //进入集团日期
        String strJoinGroupDate = Util.null2String(jsonUser.getString("zjrjt"));
        hrmResource.setStrJoinGroupDate(changeDate(strJoinGroupDate));
        String strJoinCompanyDate = Util.null2String(jsonUser.getString("zjrgs"));
        hrmResource.setStrJoinCompanyDate(changeDate(strJoinCompanyDate));
        //入职时间
        String strCompanyStartDate = Util.null2String(jsonUser.getString("zrzsj"));
        hrmResource.setStrCompanyStartDate(changeDate(strCompanyStartDate));
        //创建日期,改为入职时间
        hrmResource.setCreateDate(changeDate(strCompanyStartDate));
        //合同开始日期
        String strContractStartDate=Util.null2String(changeDate(jsonUser.getString("zjrjt")));

        hrmResource.setStrContractStartDate(strContractStartDate);
        //薪资类型
        String strSalayScope = Util.null2String(jsonUser.getString("i_trfar"));

        if ("10".equals(strSalayScope)) {
            hrmResource.setStrSalayScope("0");
        }


        //薪资区域
        String strSalaryArea = Util.null2String(jsonUser.getString("i_trfgb"));
        String strSalaryAreaOA = "";
        if ("10".equals(strSalaryArea)) {
            strSalaryAreaOA = "0";
        } else if ("20".equals(strSalaryArea)) {
            strSalaryAreaOA = "1";
        } else if ("30".equals(strSalaryArea)) {
            strSalaryAreaOA = "2";
        }
        hrmResource.setStrSalaryArea(strSalaryAreaOA);
        //薪资岗级别
        String strSalaryPositionLevel = Util.null2String(jsonUser.getString("i_trfgr"));
        String strSalaryPositionLevelOA = changeSalayLevel(strSalaryPositionLevel);
        hrmResource.setStrSalaryPositionLevel(strSalaryPositionLevelOA);
        //薪资岗档次
        String strSalaryPostGrade = Util.null2String(jsonUser.getString("i_trfst"));
        String strSalaryPostGradeOA = changeSalarGrade(strSalaryPostGrade);
        hrmResource.setStrSalaryPostGrade(strSalaryPostGradeOA);
        //养老保险社保基数
        String strPensionBase = Util.null2String(jsonUser.getString("zbetrg1"));
        hrmResource.setStrPensionBase(strPensionBase);
        //失业保险社保基数
        String strUnemployeeBase = Util.null2String(jsonUser.getString("zbetrg2"));
        hrmResource.setStrUnemployeeBase(strUnemployeeBase);
        //医疗保险社保基数
        String strMedicalBase = Util.null2String(jsonUser.getString("zbetrg3"));
        hrmResource.setStrMedicalBase(strMedicalBase);
        //工伤保险社保基数
        String strInjuryBase = Util.null2String(jsonUser.getString("zbetrg4"));
        hrmResource.setStrInjuryBase(strInjuryBase);
        //孕产保险社保基数
        String strMaternityBase = Util.null2String(jsonUser.getString("zbetrg5"));
        hrmResource.setStrMaternityBase(strMaternityBase);
        //公积金基数
        String strProvidentFundBase = Util.null2String(jsonUser.getString("zbetrg6"));
        hrmResource.setStrProvidentFundBase(strProvidentFundBase);

        //公积金缴纳地
        String strProvidentFundPlace = Util.null2String(jsonUser.getString("conargjj"));
        String strProvidentFundPlaceOA = changeCode("uf_gjjmb", "jnddm", "id", strProvidentFundPlace, rs);
        hrmResource.setStrProvidentFundPlace(strProvidentFundPlaceOA);

        //社保缴纳地
        String strSocialSecurityPlace = Util.null2String(jsonUser.getString("conarsb"));
        String strSocialSecurityPlaceOA = changeCode("uf_sbmb", "jnddm", "id", strSocialSecurityPlace, rs);
        hrmResource.setStrSocialSecurityPlace(strSocialSecurityPlaceOA);
        //税收员工类型
        String strTxgrn = Util.null2String(jsonUser.getString("txgrn"));
        String strTxgrnOA = "1";
        if ("1".equals(strTxgrn)) {
            strTxgrnOA = "0";
        }
        hrmResource.setStrTxgrn(strTxgrnOA);
        //是否劳务所得
        String strLabwk = Util.null2String(jsonUser.getString("labwk"));
        String strLabwkOA = "1";
        if ("X".equals(strLabwk)) {
            strLabwkOA = "0";
        }
        hrmResource.setStrLabwk(strLabwkOA);
        //机构类型
        String strJglx = Util.null2String(jsonUser.getString("zjglx"));
        log.info("机构类型："+strJglx);
        hrmResource.setStrJglx(strJglx);
        //员工类型
        String strYglx_sap = Util.null2String(jsonUser.getString("zyglx"));
        log.info("sap员工类型："+strYglx_sap);
        String yglx = getYglx(strYglx_sap);
        log.info("OA员工类型："+yglx);
        hrmResource.setStrYglx(yglx);
        //工作地区
        String strGzdq_sap = Util.null2String(jsonUser.getString("zgzdq"));
        log.info("sap工作地区："+strGzdq_sap);
        String gzdq = getGzdq(strGzdq_sap);
        log.info("OA工作地区："+gzdq);
        hrmResource.setStrGzdq(gzdq);
        //岗位序列
        String strGwxl = Util.null2String(jsonUser.getString("zngwxl"));
        log.info("岗位序列："+strGwxl);
        hrmResource.setStrGwxl(strGwxl);
        //名称(AD):查询表uf_qjt_adxsmc;查询条件ygh(员工号);查询字段xsmc
        String strNameAd_OA = changeCode("uf_qjt_adxsmc", "ygh", "xsmc", strWorkcode, rs);
        log.info("显示名(AD)："+strNameAd_OA);
        hrmResource.setStrNameAd(strNameAd_OA);
        //岗位名称(AD):查询表HRMJOBTITLES;查询条件ID(岗位id);查询字段JOBTITLENAME
        String strGwNameAd_OA = changeCode("HRMJOBTITLES", "ID", "JOBTITLENAME", strJobtitleid, rs);
        log.info("岗位(AD):"+strGwNameAd_OA);
        hrmResource.setStrGwNameAd(strGwNameAd_OA);
        //部门(AD):查询表hrmdepartment;查询条件ID(部门id);查询字段departmentname
        String strDepartmentAd_OA = changeCode("hrmdepartment", "ID", "departmentname", strDepartId, rs);
        log.info("部门(AD):"+strDepartmentAd_OA);
        hrmResource.setStrDepartmentAd(strDepartmentAd_OA);
        //公司(AD)：查询表uf_qjt_syb_jc;查询条件fb(分部id);查询字段：简称字段(sybjc)
        String strCompanytAd_OA = changeCode("uf_qjt_syb_jc", "fb", "sybjc", strSubId, rs);
        log.info("公司(AD):"+strCompanytAd_OA);
        hrmResource.setStrCompanytAd(strCompanytAd_OA);

        //岗级范围
        String strGjfw = Util.null2String(jsonUser.getString("zgwdj"));
        log.info("岗级范围："+strGjfw);
        hrmResource.setStrGjfw(strGjfw);
        return hrmResource;
    }


    /**
     * 薪资档次
     */

    public String changeSalarGrade(String strSalaryGrade) {
        String strSalaryGradeOA = "";
        if ("0".equals(strSalaryGrade)) {
            strSalaryGradeOA = "0";
        } else if ("1".equals(strSalaryGrade)) {
            strSalaryGradeOA = "1";
        } else if ("2".equals(strSalaryGrade)) {
            strSalaryGradeOA = "2";
        } else if ("3".equals(strSalaryGrade)) {
            strSalaryGradeOA = "3";
        } else if ("4".equals(strSalaryGrade)) {
            strSalaryGradeOA = "4";
        } else if ("5".equals(strSalaryGrade)) {
            strSalaryGradeOA = "5";
        } else if ("6".equals(strSalaryGrade)) {
            strSalaryGradeOA = "6";
        }
        return strSalaryGradeOA;
    }

    /**
     * 薪资级别转换
     *
     * @param strSalaryLeavel
     * @return
     */
    public String changeSalayLevel(String strSalaryLeavel) {
        String strSalaryOA = "";
        if ("0".equals(strSalaryLeavel)) {
            strSalaryOA = "0";
        } else if ("001".equals(strSalaryLeavel)) {
            strSalaryOA = "1";
        } else if ("002".equals(strSalaryLeavel)) {
            strSalaryOA = "2";
        } else if ("003".equals(strSalaryLeavel)) {
            strSalaryOA = "3";
        } else if ("004".equals(strSalaryLeavel)) {
            strSalaryOA = "4";
        } else if ("005".equals(strSalaryLeavel)) {
            strSalaryOA = "5";
        } else if ("006".equals(strSalaryLeavel)) {
            strSalaryOA = "6";
        } else if ("007".equals(strSalaryLeavel)) {
            strSalaryOA = "7";
        } else if ("008".equals(strSalaryLeavel)) {
            strSalaryOA = "8";
        } else if ("009".equals(strSalaryLeavel)) {
            strSalaryOA = "9";
        } else if ("010".equals(strSalaryLeavel)) {
            strSalaryOA = "10";
        } else if ("011".equals(strSalaryLeavel)) {
            strSalaryOA = "11";
        } else if ("012".equals(strSalaryLeavel)) {
            strSalaryOA = "12";
        } else if ("013".equals(strSalaryLeavel)) {
            strSalaryOA = "13";
        } else if ("014".equals(strSalaryLeavel)) {
            strSalaryOA = "14";
        } else if ("015".equals(strSalaryLeavel)) {
            strSalaryOA = "15";
        } else if ("016".equals(strSalaryLeavel)) {
            strSalaryOA = "16";
        } else if ("017".equals(strSalaryLeavel)) {
            strSalaryOA = "17";
        } else if ("018".equals(strSalaryLeavel)) {
            strSalaryOA = "18";
        } else if ("019".equals(strSalaryLeavel)) {
            strSalaryOA = "19";
        } else if ("020".equals(strSalaryLeavel)) {
            strSalaryOA = "20";
        } else if ("021".equals(strSalaryLeavel)) {
            strSalaryOA = "21";
        } else if ("022".equals(strSalaryLeavel)) {
            strSalaryOA = "22";
        } else if ("023".equals(strSalaryLeavel)) {
            strSalaryOA = "23";
        } else if ("024".equals(strSalaryLeavel)) {
            strSalaryOA = "24";
        } else if ("025".equals(strSalaryLeavel)) {
            strSalaryOA = "25";
        } else if ("026".equals(strSalaryLeavel)) {
            strSalaryOA = "26";
        } else if ("A".equals(strSalaryLeavel)) {
            strSalaryOA = "27";
        } else if ("B".equals(strSalaryLeavel)) {
            strSalaryOA = "28";
        } else if ("C".equals(strSalaryLeavel)) {
            strSalaryOA = "29";
        } else if ("D".equals(strSalaryLeavel)) {
            strSalaryOA = "30";
        } else if ("E".equals(strSalaryLeavel)) {
            strSalaryOA = "31";
        } else if ("F".equals(strSalaryLeavel)) {
            strSalaryOA = "32";
        } else if ("G".equals(strSalaryLeavel)) {
            strSalaryOA = "33";
        } else if ("H".equals(strSalaryLeavel)) {
            strSalaryOA = "34";
        } else if ("I".equals(strSalaryLeavel)) {
            strSalaryOA = "35";
        } else if ("J".equals(strSalaryLeavel)) {
            strSalaryOA = "36";
        } else if ("K".equals(strSalaryLeavel)) {
            strSalaryOA = "37";
        }

        return strSalaryOA;

    }

    /**
     * 是否开通ad转化
     */

    public String changeAD(String strIsOpenAD) {
        //返回值
        String strResult = "";
        if ("Y".equals(strIsOpenAD)) {
            strResult = "1";
        } else {
            strResult = "0";
        }
        return strResult;
    }

    /**
     * 日期格式转换
     *
     * @param strDate 待转化日期yyyyMMdd
     * @return 返回转换为String格式日期yyyy-MM-dd
     */
    private String changeDate(String strDate) {
        if ("00000000".equals(strDate)) {
            return "";
        }
//        log.info("待转化的日期:" + strDate);
        //返回日期格式
        String strReturnDate = "";
        //注意：SimpleDateFormat构造函数的样式与strDate的样式必须相符
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd"); //加上时间
        //必须捕获异常
        try {
            Date date = simpleDateFormat.parse(strDate);
            strReturnDate = sDateFormat.format(date);
        } catch (ParseException px) {
            px.printStackTrace();
        }
//        log.info("转换后的日期:" + strReturnDate);
        return strReturnDate;

    }


    /**
     * 码表转换
     *
     * @param strCodeTable 码表名称,strCondition 条件字段名称,strReturn查询的字段名称,
     *                     strConditionVal查询条件值,rs数据库操作
     */

    private String changeCode(String strCodeTable, String strCondition, String strReturn, String strConditionVal, RecordSet rs) {
        String strReturnVal = "";
        //oa与sap对应关系,根据sap对应的值,返回OA值
        String sql = "select " + strReturn + " from " + strCodeTable + " where " + strCondition + " ='" + strConditionVal + "'";
//        log.info("查询码表值:" + sql);
        rs.executeQuery(sql);
        if (rs.next()) {
            strReturnVal = Util.null2String(rs.getString(strReturn));
        }
//        log.info("码表返回值:" + strReturnVal);
        return strReturnVal;
    }

    /**
     * 根据岗位id查询部门id
     */

    public String getDepartmentId(String jobid, RecordSet rs) {
        //返回部门id
        String strDepart = "";
        String sql = "select jobdepartmentid from hrmjobtitles where id='" + jobid + "'";
        rs.executeQuery(sql);
        rs.next();
        strDepart = Util.null2String(rs.getString("jobdepartmentid"));
        return strDepart;
    }

    /**
     * 根据部门id查询分部id
     */

    public String getSubid(String strDepid, RecordSet rs) {
        //返回分部id
        String strSubid = "";
        String sql = "select subcompanyid1 from hrmdepartment where id='" + strDepid + "'";
        rs.executeQuery(sql);
        rs.next();
        strSubid = Util.null2String(rs.getString("subcompanyid1"));
        return strSubid;
    }

    /**
     * 户口类型转换
     *
     * @param strSAP 1 非农业户口 2 农业户口 3 其他
     * @return 0 非农业户口 1 农业户口 2 其他
     */

    private String changeHkType(String strSAP) {
        //OA类型返回值
        String strOA = "";
        if ("1".equals(strSAP)) {
            strOA = "0";
        } else if ("2".equals(strSAP)) {
            strOA = "1";
        } else {
            strOA = "2";
        }
        return strOA;
    }

    /**
     * 婚姻状态转换
     *
     * @param strSAP 1未婚2已婚 3其它
     * @return 0 未婚 1 已婚 2 其他
     */
    private String changeMaritalType(String strSAP) {
        //OA类型返回值
        String strOA = "";
        if ("1".equals(strSAP)) {
            strOA = "0";
        } else if ("2".equals(strSAP)) {
            strOA = "1";
        } else {
            strOA = "2";
        }
        return strOA;
    }

    /***
     * 根据地区编码查找工作地区id
     * @param strDqbm
     * @return
     */
    private String getGzdq(String strDqbm){
        String strResult="";
        RecordSet rs=new RecordSet();
        String strSql="SELECT * FROM UF_GZDQ WHERE DQBM='"+strDqbm+"'";
        rs.execute(strSql);
        while (rs.next()){
            strResult=Util.null2String(rs.getString("id"));
        }
        return strResult;
    }

    /***
     * 根据员工类型编码查找员工类型id
     * @param strYglx
     * @return
     */
    private String getYglx(String strYglx){
        String strResult="";
        RecordSet rs=new RecordSet();
        String strSql="SELECT * FROM UF_JTRSAQJBDYB WHERE RYLXBM='"+strYglx+"'";
        rs.execute(strSql);
        while (rs.next()){
            strResult=Util.null2String(rs.getString("id"));
        }
        return strResult;
    }

//    /***
//     * 根据不同条件查询不同数据
//     * @param ctype
//     * @param param
//     * @return
//     */
//    private String getXsmc(String ctype,String param){
//        String strSql="";
//        String result="";
//        RecordSet rs=new RecordSet();
//        if("xsmc".equals(ctype)){
//            //根据员工号查询AD对应的显示名称
//            strSql="SELECT xsmc FROM uf_qjt_adxsmc WHERE YGH='"+param+"'";
//        }else if("jc".equals(ctype)){
//            //根据分部id查询对应的简称
//            strSql="SELECT sybjc FROM uf_qjt_syb_jc WHERE fb='"+param+"'";
//        }
//        rs.execute(strSql);
//        while (rs.next()){
//            result=Util.null2String(rs.getString(0));
//        }
//        return result;
//
//    }


}
